Strava Information Plot pydeck

code
algorithms
Python
Strava
Author

Marco Aguirre

Published

May 27, 2024

#pip install pydeck
import pydeck as pdk
import pandas as pd
import ast 

Read Dataset

df = pd.read_csv("dataset.csv")
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 5817 entries, 0 to 5816
Data columns (total 10 columns):
 #   Column                Non-Null Count  Dtype  
---  ------                --------------  -----  
 0   id                    5817 non-null   object 
 1   distance              5817 non-null   float64
 2   elevation_high        5817 non-null   float64
 3   elevation_low         5817 non-null   float64
 4   start_latlng          5817 non-null   object 
 5   climb_category        5817 non-null   int64  
 6   total_elevation_gain  5817 non-null   float64
 7   effort_count          5817 non-null   int64  
 8   athlete_count         5817 non-null   int64  
 9   star_count            5817 non-null   int64  
dtypes: float64(4), int64(4), object(2)
memory usage: 454.6+ KB

Get latitude and Longitude

df["start_latlng"] = df.start_latlng.apply(ast.literal_eval)
df["lat"] = df.start_latlng.apply(lambda x:x[0])
df["lng"] = df.start_latlng.apply(lambda x:x[1])

Plot Elevation High



column_layer = pdk.Layer(
    "ColumnLayer",
    data=df,
    get_position=["lng", "lat"],
    get_elevation="elevation_high",
    radius=50,
    pickable=True,
    auto_highlight=True,
    get_fill_color = ["252","82","0" ,140]
)

tooltip = {
    "html": "<b>{elevation_high}</b> meters elevation, climb category <b>{climb_category}</b> NTD/sqm",
    "style": {"background": "grey", "color": "white", "font-family": '"Helvetica Neue", Arial', "z-index": "10000"},
}
view_state = pdk.ViewState(
    longitude=-78.46576413139701,
    latitude=-0.1988402847200632,
    zoom=6,
    min_zoom=9,
    max_zoom=15,
    pitch=40.5,
    bearing=-27.36)

r = pdk.Deck(
    column_layer,
    initial_view_state=view_state,
    tooltip=tooltip,
)

r.to_html("column_layer.html")
# Define a layer to display on a map
layer = pdk.Layer(
    "HexagonLayer",
    df[["lng", "lat",'elevation_high']],
    get_position=["lng", "lat"],
    elevation_scale=50,
    pickable=True,
    elevation_range=[0, 1500],
    extruded=True,
    coverage=1,
)
# Set the viewport location -0.1988402847200632, -78.46576413139701
view_state = pdk.ViewState(
    longitude=-78.46576413139701,
    latitude=-0.1988402847200632,
    zoom=6,
    min_zoom=8,
    max_zoom=15,
    pitch=40.5,
    bearing=-27.36)
# Render
r = pdk.Deck(layers=[layer], initial_view_state=view_state)
r.to_html("hexagon_layer.html")